package com.tom.architect.day07.diy;

public class MainActivity extends Activity {
	private TextView mTextView;

	private Handler mHandler = new Handler() {
		@Override
		public void handleMessage(Message msg) {
			mTextView.setText((String) msg.obj);
			System.out.println("线程名称2：" + Thread.currentThread());
		};
	};

	@Override
	public void onCreate() {
		super.onCreate();
		System.out.println("onCreate  执行了");
		mTextView = findViewById(R.id.text_view);

		new Thread() {
			public void run() {
//				mTextView.setText("asdf"); // 子线程直接更新UI，报错。
				try {
					Thread.sleep(2000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
				System.out.println("线程名称1：" + Thread.currentThread());
				Message message = new Message();
				message.obj = "后台数据";
				mHandler.sendMessage(message);
			};
		}.start();
	}

	@Override
	public void onResume() {
		super.onResume();
		System.out.println("onResume 执行了");
	}
}
